package com.example.saiweisi.service.impl.userService;

import com.example.saiweisi.controller.dto.ClothesInfoDTO;
import com.example.saiweisi.mapper.userMapper.ClothesMapper;
import com.example.saiweisi.model.ClothesKind;
import com.example.saiweisi.model.ClothesKindMaterial;
import com.example.saiweisi.model.ClothesMaterialWashKind;
import com.example.saiweisi.service.interf.IClothesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ClothesService implements IClothesService {
    @Autowired
    ClothesMapper clothesMapper;

    @Override
    public List<ClothesInfoDTO> getClothesByUserId(Integer userId) {

        List<ClothesKindMaterial> clothesByUserId = clothesMapper.getClothesByUserId(userId);
        //每一个对象中存储衣物种类信息和衣物材质信息
        List<ClothesInfoDTO> clothesInfoDTOList = new ArrayList<>();
        for (int i = 0; i < clothesByUserId.size(); i++) {
            //实例化这两个对象
            ClothesKind clothesKind = new ClothesKind();
            ClothesMaterialWashKind clothesMaterialWashKind = new ClothesMaterialWashKind();
            //将查询到的衣物信息copy到这两个对象中
            BeanUtils.copyProperties(clothesByUserId.get(i), clothesKind);
            clothesKind.setClothesKindId((int) clothesByUserId.get(i).getClothesKindId());
//            clothesKind.setClothesKindName(clothesByUserId.get(i).getClothesKindName());
//            clothesKind.setClothesPrice(clothesByUserId.get(i).getClothesPrice());


            BeanUtils.copyProperties(clothesByUserId.get(i), clothesMaterialWashKind);
//            clothesMaterialWashKind.setClothesMaterialId(clothesByUserId.get(i));
            //将这两个规范化的对象存储到对象列表的一个对象中去
            ClothesInfoDTO clothesInfoDTO = new ClothesInfoDTO();
            clothesInfoDTO.setClothesMaterial(clothesMaterialWashKind);
            clothesInfoDTO.setClothesKind(clothesKind);
            clothesInfoDTO.setClothesId(clothesByUserId.get(i).getClothesId());
            //存储对象列表
            clothesInfoDTOList.add(i, clothesInfoDTO);
        }
        return clothesInfoDTOList;
    }

    @Override
    public void isbad(Integer clothesId) {
        clothesMapper.isbad(clothesId);
    }

    @Override
    public void nextstep(Integer clothesId) {
        clothesMapper.nextstep(clothesId);
    }

    @Override
    public void finish(Integer clothesId) {
        clothesMapper.finish(clothesId);
    }
}
